﻿#Region "Copyright"

' Copyright 2007 Ben Reichelt - http://benreichelt.net
' 
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
' 
'     http://www.apache.org/licenses/LICENSE-2.0
' 
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.


#End Region

Imports NUnit.Framework
Imports SqlPlastic
Imports System.Xml.Linq

<TestFixture()> _
Public Class MetaDataColumnTests

    Private metaData As XmlMetaData

    <SetUp()> _
    Public Sub Setup()
        metaData = ObjectMother.CreateDefaultMetaData
    End Sub

    <Test()> _
    Public Sub RenameColumnTest()
        Dim type As MetaDataType = metaData.FindType(C.Type1Name)
        Dim column As MetaDataColumn = type.Column(C.Column1Name)
        column.RenameTo("Ben")
        Assert.AreEqual("Ben", column.MemberName)
        column = type.Column(C.Column1Name)
        Assert.AreEqual("Ben", column.MemberName)
    End Sub

    <Test()> _
    Public Sub RenameColumnMissingAttributeTest()
        Dim type As MetaDataType = metaData.FindType(C.Type1Name)
        Dim column As MetaDataColumn = type.Column(C.ColumnWithNoMember)
        column.RenameTo("Ben")
        Assert.AreEqual("Ben", column.MemberName)
        column = type.Column(C.ColumnWithNoMember)
        Assert.AreEqual("Ben", column.MemberName)
    End Sub

    <Test()> _
    Public Sub RenameColumnWithAssociationsTest()
        Dim type As MetaDataType = metaData.FindType(C.Type2Name)
        Dim column As MetaDataColumn = type.Column(C.Column1Name)
        Dim originalList As List(Of MetaDataAssociation) = metaData.FindAllAssociationsByColumn(C.Column1Member)
        Assert.Greater(originalList.Count, 0)
        column.RenameTo("Ben")
        Dim newList As List(Of MetaDataAssociation) = metaData.FindAllAssociationsByColumn("Ben")
        Assert.AreEqual(originalList.Count, newList.Count)
    End Sub

    <Test()> _
    Public Sub GetMemberNameDoesntExist()
        Dim type As MetaDataType = metaData.FindType(C.Type1Name)
        Dim col As MetaDataColumn = type.Column(C.ColumnWithNoMember)
        Assert.AreEqual(String.Empty, col.MemberName)
    End Sub


End Class
